<!--A Design by W3layouts
Author: W3layout
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
-->
<!DOCTYPE HTML>
<html>

<head>
	<title>在线OJ</title>
	<script src="js/jquery-2.1.0.min.js"></script>
	<!-- Meta-Tags -->
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta charset="utf-8">

	<meta name="keywords" content="Agent Contact Form Responsive Widget,Login form widgets, Sign up Web forms , Login signup Responsive web form,Flat Pricing table,Flat Drop downs,Registration Forms,News letter Forms,Elements"
	/>
	<script>
		addEventListener("load", function () {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0, 1);
		}
	</script>
	<!-- //Meta-Tags -->
	<!-- Stylesheets -->
	<link href="css/style.css" rel='stylesheet' type='text/css' />
	<!--// Stylesheets -->
	<!--fonts-->
	<link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet">
	<!--//fonts-->
</head>

<body>
	<h1>未来之子</h1>
	<div class="w3ls-login">
		<!-- form starts here -->
		<form action="#" method="post">
			<div class="agile-field-txt">
				<label>
					 标题 :</label>
				<input type="text" name="name" id="title" />
			</div>
			<div class="agile-field-txt">
				<label>
					 描述 :</label>
				<input type="email" name="email" id="description" placeholder=" " required="" />
			</div>
			<div class="agile-field-txt">
				<label>
					答题 :</label>
				<textarea name="Message" placeholder=" " id="templateCode" required=""></textarea>
			</div>
			<div class="agile-field-txt">
				<label>
					结果 :</label>
				<textarea name="Message" placeholder=" " id="answer" required=""></textarea>
			</div>
			<!-- //script for show password -->
			<div class="w3ls-login  w3l-sub">
				<input type="button" onclick="tijiao()" value="提交">
			</div>
		</form>
	</div>
	<script>
		$.ajax({
			url:"oj/selectOne" + location.search,
			type:"get",
			success: function(data){
				console.log("进入 success 函数" + data.status)
				buildBlogs(data.body);
			},
		})

		function buildBlogs(data){
			jQuery("#title").val("题号:" + data.id + "  " + "题目:" + data.title + "  " + "级别:" + data.level)
			jQuery("#description").val(data.description)
			let templateCode = document.querySelector("#templateCode");
			templateCode.innerHTML = data.templateCode;
		}


		function tijiao(){
			let templateCode = document.querySelector("#templateCode");
			let tmp = {
				"id" : getParam("id"),
				"templateCode" : templateCode.value
			}
			let templateCodeJson = JSON.stringify(tmp);
			$.ajax({
				url:"oj/task",
				type:"post",
				data:templateCodeJson,
				contentType: "application/json;charset=UTF-8",
				success: function(data){
					console.log("进入 success 函数" + data.status)
					answer(data.body);
				},
			})
			function answer(data){
				jQuery("#answer").val("执行结果: " + data.error + "\n" +
						"出错原因: " + data.reason + "\n" +
						"标准输出: " + data.stdout + "\n" +
						"标准错误: " + data.stderr);
			}
		}
		function getParam (key){
			var params = location.search;
			params = params.substring(1);
			var paramArr = params.split("&");
			for (var i = 0; i < paramArr.length;i++){
				var item = paramArr[i].split("=");
				if (item[0] == key){
					return item[1];
				}
			}
			return null;
		}
	</script>
</body>
</html>